package cn.south.campus.business.model.vo;

import cn.south.campus.business.model.entity.WalletLog;
import cn.south.campus.business.model.enums.WalletEnums;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/14 14:03
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class WalletLogVo extends BaseVO {
    private Long userId;

    /**
     * 金额
     */
    private String amount;

    /**
     * 类型
     *
     * @see WalletEnums.WalletTypeEnums
     */
    private Integer type;

    /**
     * 状态
     */
    private Integer status;

    /**
     * 描述
     */
    private String description;

    /**
     * 关联订单
     */
    private String orderNo;

    public static WalletLogVo convert(WalletLog walletLog) {
        if (walletLog == null) {
            return null;
        }

        WalletLogVo walletLogVo = new WalletLogVo();
        walletLogVo.setId(walletLog.getId());
        walletLogVo.setUserId(walletLog.getUserId());
        switch (walletLog.getType()) {
            case 1:
            case 4:
            case 5:
                walletLogVo.setAmount("+" + walletLog.getAmount().toString());
                break;
            case 2:
            case 3:
                walletLogVo.setAmount("-" + walletLog.getAmount().toString());
                break;
            default:
                walletLogVo.setAmount(walletLog.getAmount().toString());
        }
        walletLogVo.setStatus(walletLog.getStatus());
        walletLogVo.setCreateTime(DateUtil.format(walletLog.getCreateTime()));
        walletLogVo.setType(walletLog.getType());
        walletLogVo.setDescription(walletLog.getDescription());
        walletLogVo.setOrderNo(walletLog.getOrderNo());
        return walletLogVo;
    }
}
